package com.raidpoints.client;

import java.util.ArrayList;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.user.client.ui.ListBox;

public class NIListBox extends ListBox{
	
	ListBox test;
	
	ArrayList<Boolean> hist;
	
	public NIListBox(){
		hist = new ArrayList<Boolean>();
		this.addChangeHandler(new ChangeHandler(){
			@Override
			public void onChange(ChangeEvent event) {
				NIListBox tb = NIListBox.this;
				int ch = -1;
				for(int i = 0; i < tb.getItemCount(); i++){
					if(tb.isItemSelected(i)) ch = (ch == -1 ? i : -2);
				}
				if(ch == -1) return;
				hist.set(ch, !hist.get(ch));
				for(int i = 0; i < hist.size(); i++) tb.setItemSelected(i, hist.get(i));
			}
		});


	}
	
	@Override
	public void clear(){
		hist.clear();
		super.clear();
	}
	
	
	@Override
	public void addItem(java.lang.String item){
		hist.add(false);
		super.addItem(item);
	}
	
	@Override
	public void removeItem(int index){
		hist.remove(index);
		super.removeItem(index);
	}
	
	@Override
	public void setItemSelected(int index, boolean selected){
		hist.set(index, selected);
		super.setItemSelected(index, selected);
	}
	
	
	
	
}
